package com.xixibaby.mybatis.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.xixibaby.core.mybatis.JoinInterceptor;
import com.xixibaby.core.mybatis.XixibabyLogicSqlInjector;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * mybatis-plus配置
 * @author mall
 * @date 2018/12/13
 */
@Import(DateMetaObjectHandler.class)
@MapperScan({"com.twfhousekeeping.**.mapper","com.xixibaby.**.mapper"})
public class DefaultMybatisPlusConfig {
    /**
     * 分页插件，自动识别数据库类型
     */

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    public JoinInterceptor joinInterceptor() {
        return new JoinInterceptor();
    }

    @Bean
    public OptimisticLockerInterceptor optimisticLoker() {
        return new OptimisticLockerInterceptor();

    }



    /**
     * 逻辑删除 插件
     * @return
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new XixibabyLogicSqlInjector();
    }

    /**
     * 打印 sql，性能分析拦截器，不建议生产使用
     * 设置 dev test 环境开启
     */
    @Bean
   // @Profile("local")
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }
}
